/*
 * Copyright 2010 GP Software
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Launcher.java | Created on 24 04 2010
 */
package org.gp.gpetl.client;

import org.gp.gpetl.exception.DataHandlingException;
import org.gp.gpetl.handler.DataHandler;
import org.gp.gpetl.util.ContextUtil;

/**
 * Launches the ETL process
 *
 * @author Paul Augustine C. Mendoza
 * @since 1.0
 */
public class Launcher {

    /**
     * The status message identifier
     */
    private static final String STATUS_MSG = "Process completed in ";

    /**
     * This launches the application
     *
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        System.out.println("Launching GP ETL");
        // Log the start time
        long start = System.currentTimeMillis();

        DataHandler dataHandler =
                (DataHandler) ContextUtil.getBean("handlingService");
        try {
            dataHandler.handle();
        } catch (DataHandlingException e) {
            e.printStackTrace(); 
        }

        // Log the end time
        long duration = System.currentTimeMillis() - start;
        if (duration < 1000) {
            System.out.println(STATUS_MSG + duration + " milliseconds.");
        } else {
            System.out.println(STATUS_MSG + (duration / 1000) + " second(s).");
        }
        System.exit(0);
    }
}
